<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;
use think\Config;

class Cases extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    //首页
    public function index()
    {
        $where = [
            'show' => 1
        ];
        $flag = $this->request->param('flag');
        if($flag){
            $where['flag'] = ['like','%'.$flag.'%'];
        }
        $data = Db::name('project')->where($where)->paginate(8);
        $page = $data->render();
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->view->fetch();
    }


    //案例中心
    public function index_ajax()
    {
        $param = $this->request->param();
        $key = xykeepFilterSql($param['id']);
        $recmd_data = Db::name('project')->where([
            'show' => 1,
            'recommend' => 1,
            'flag' => ['like','%'.$key.'%']
        ])->limit(0,4)->select();
        $this->assign('recmd_data',$recmd_data);
        Config::set('default_ajax_return','html');
        return $this->view->fetch('cases/recmd_ajax');
    }



    //案例详情
    public function detail()
    {
        $id = input('id/d');
        $data = Db::name('project')->where(['id'=>$id,'show'=>1])->find();
        $this->assign('data',$data);

        $relate_data = Db::name('project')->where('flag',$data['flag'])->limit(0,4)->select();
        $this->assign('relate_data',$relate_data);

        return $this->view->fetch();
    }
}
